<?php
namespace ManiaLivePlugins\MLEPP\ServerInfo\Gui\Controls;

use ManiaLib\Gui\Elements\Button;
use ManiaLive\Gui\Windowing\Controls\Pager;
use ManiaLive\PluginHandler\PluginHandler;
use ManiaLivePlugins\MLEPP\ServerInfo\ServerInfo;
use ManiaLive\Gui\Handler\GuiHandler;
use ManiaLive\Database\Connection;
use ManiaLive\Threading\Commands\Command;
use ManiaLive\Threading\ThreadPool;
use ManiaLib\Gui\Elements\Label;
use ManiaLib\Gui\Elements\Quad;
use ManiaLive\Gui\Windowing\Controls\Frame;
use ManiaLib\Gui\Layouts\Column;
use ManiaLib\Gui\Layouts\Line;
use ManiaLib\Gui\Elements\Bgs1InRace;
use ManiaLib\Gui\Elements\Format;

class ServerLinksTab extends \ManiaLive\Gui\Windowing\Controls\Tab
{
    private $frame;
	private $config;

    function initializeComponents()
    {
		$this->config = Condig::getInstance()->config;

		$btnHomepage = new Button();
		if( !empty($this->config->ServerSite) ) {
		$btnHomepage->setUrl($this->config->ServerSite);
		$color = '$000';
		}
		else {
		$color = '$aaa';
		}
		$btnHomepage->setText($color.'Get detailed information about all our servers');
        $btnHomepage->setPosition(2,1);
		$btnHomepage->setStyle(Button::CardButtonSmallWide);
		$btnHomepage->setVisibility(true);
		$this->addComponent($btnHomepage);

		$this->frame = new Frame();
		$this->frame->applyLayout(new Column());
		$this->frame->setPosY(6);
		$this->frame->setSize($this->sizeX, 50);
		$this->addComponent($this->frame);
    }


    function joinList()
    {
        //$this->frame->clearItems();
		$this->frame->clearComponents();
		$i = 0;
		foreach ($this->config->serverNames as $data)
        {

			$frame = new Frame();
//			$frame->applyLayout(new Flow());
			$frame->setSize(45, 3);


	        $item = new Label();
			$item->setText($data);
         	$item->setPosition(2,0);
		    $frame->addComponent($item);

		$btn = new Quad();
		$btn->setStyle(Bgs1InRace::Bgs1InRace);
		$btn->setSubStyle(Bgs1InRace::BgButton);
		$btn->setSize(10,3);
       	$btn->setPosition(25,0);
		$btn->setManialink('tmtp://#join='.$this->config->serverLogins[$i]);
		$frame->addComponent($btn);

		$lbl = new Label();
		$lbl->setTextSize(2);
		$lbl->setStyle(Format::TextButtonNav);
		$lbl->setPosX(25+2);
		$lbl->setPosY((3 / 2));
		$lbl->setValign("center");
		$lbl->setSize(10,3);
		$lbl->setText('$222Join Server');
		$lbl->setScale(0.7);
		$frame->addComponent($lbl);

		$btn2 = new Quad();
		$btn2->setStyle(Bgs1InRace::Bgs1InRace);
		$btn2->setSubStyle(Bgs1InRace::BgButton);
		$btn2->setSize(10,3);
       	$btn2->setPosition(35,0);
		$btn2->setManialink('tmtp://#addfavourite='.$this->config->serverLogins[$i]);
		$frame->addComponent($btn2);

		$lbl2 = new Label();
		$lbl2->setTextSize(2);
		$lbl2->setStyle(Format::TextButtonNav);
		$lbl2->setPosX(35+2);
		$lbl2->setPosY((3 / 2));
		$lbl2->setValign("center");
		$lbl2->setSize(10,3);
		$lbl2->setText('$222Add Favo');
		$lbl2->setScale(0.7);
		$frame->addComponent($lbl2);

		$this->frame->addComponent($frame);

		$i++;
		}

    }


    function onResize()
    {
	    //	$this->btnServerPage->setPosition(2, 1);
       // $this->pgServerLinks->setSize($this->sizeX, $this->sizeY-5);

    }

	function beforeDraw()
	{

	}

}

?>